﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraLayout;
    using DevExpress.XtraLayout.Utils;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Common;
    using DevExpress.XtraGrid.Views.Base;

    public class xuc03bTBH : Common.xucBase
    {
        private GridColumn colContentChange;
        private GridColumn colEmployeeCode;
        private GridColumn colEmployeeName;
        private GridColumn colHealthInsuranceCode;
        private GridColumn colNewContent;
        private GridColumn colOldContent;
        private GridColumn colReason;
        private GridColumn colSocialInsuranceCode;
        private IContainer components;
        private GridView gbList;
        private GridControl gcList;
        private LayoutControl layoutControl1;
        private LayoutControlGroup layoutControlGroup1;
        private LayoutControlGroup layoutControlGroup2;
        private LayoutControlItem layoutControlItem1;
        private Guid m_InsuranceTableListID;
        private RepositoryItemPictureEdit rptPhoto;

        public event ItemSelectedEventHander ItemSelected;

        public xuc03bTBH()
        {
            this.components = null;
            this.m_InsuranceTableListID = Guid.Empty;
            this.InitializeComponent();
            this.Init();
        }

        public xuc03bTBH(Guid InsuranceTableListID)
        {
            this.components = null;
            this.m_InsuranceTableListID = Guid.Empty;
            this.InitializeComponent();
            this.m_InsuranceTableListID = InsuranceTableListID;
            this.Init();
        }

        private void Add()
        {
        }

        public void Change()
        {
            HRM_INSURANCE_MODIFY hrm_insurance_modify = new HRM_INSURANCE_MODIFY();
            object focusedRowCellValue = this.gbList.GetFocusedRowCellValue("ModifyID");
            if (focusedRowCellValue != null)
            {
                base.SetWaitDialogCaption("Đang kiểm tra dữ liệu....");
                if (hrm_insurance_modify.Get(new Guid(focusedRowCellValue.ToString())) != "OK")
                {
                    this.DoHide();
                    XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    this.DoHide();
                }
            }
        }

        public void Delete()
        {
            bool flag = false;
            int[] selectedRows = this.gbList.GetSelectedRows();
            if (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)
            {
                string str;
                object rowCellValue;
                base.SetWaitDialogCaption("Đang x\x00f3a...");
                HRM_INSURANCE_MODIFY hrm_insurance_modify = new HRM_INSURANCE_MODIFY();
                for (int i = selectedRows.Length; i > 0; i--)
                {
                    flag = true;
                    rowCellValue = this.gbList.GetRowCellValue(selectedRows[i - 1], "ModifyID");
                    if (rowCellValue != null)
                    {
                        SYS_LOG.Insert("Danh S\x00e1ch Đề Nghị Điều Chỉnh Hồ Sơ Tham Gia BHXH, BHYT", "Xo\x00e1", rowCellValue.ToString());
                        str = hrm_insurance_modify.Delete(new Guid(rowCellValue.ToString()));
                        if (str == "OK")
                        {
                            this.gbList.DeleteRow(selectedRows[i - 1]);
                        }
                        else if (str != "OK")
                        {
                            MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\r\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                }
                this.DoHide();
                if (!flag && (hrm_insurance_modify.GetList().Rows.Count != 0))
                {
                    rowCellValue = this.gbList.GetFocusedRowCellValue("ModifyID");
                    if (rowCellValue != null)
                    {
                        SYS_LOG.Insert("Danh S\x00e1ch Đề Nghị Điều Chỉnh Hồ Sơ Tham Gia BHXH, BHYT", "Xo\x00e1", rowCellValue.ToString());
                        base.SetWaitDialogCaption("Đang x\x00f3a...");
                        str = hrm_insurance_modify.Delete(new Guid(rowCellValue.ToString()));
                        if (str == "OK")
                        {
                            this.gbList.DeleteRow(this.gbList.FocusedRowHandle);
                        }
                        else if (str != "OK")
                        {
                            MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\r\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        this.DoHide();
                    }
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        protected override bool ExportPermision()
        {
            base._exportView = this.gbList;
            SYS_LOG.Insert("Danh S\x00e1ch Đề Nghị Điều Chỉnh Hồ Sơ Tham Gia BHXH, BHYT", "Xuất");
            return base.ExportPermision();
        }

        private void frm_Added(object sender, HRM_INSURANCE_MODIFY Item)
        {
            this.ReLoad();
        }

        private void frm_Updated(object sender, HRM_INSURANCE_MODIFY Item)
        {
            this.ReLoad();
        }

        private void gbList_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.RowHandle == -2147483648)
            {
                e.Handled = true;
                e.Painter.DrawObject(e.Info);
                Rectangle bounds = e.Bounds;
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x3f, 0xa5, 0xa5, 0)), bounds);
                bounds.Height--;
                bounds.Width--;
                e.Graphics.DrawRectangle(Pens.Blue, bounds);
            }
            int rowHandle = e.RowHandle;
            if (rowHandle >= 0)
            {
                rowHandle++;
                e.Info.DisplayText = rowHandle.ToString();
            }
        }

        private void gbList_DoubleClick(object sender, EventArgs e)
        {
            if (this.gbList.RowCount != 0)
            {
                this.Change();
            }
        }

        private void gbList_KeyDown(object sender, KeyEventArgs e)
        {
            this.ucList_ListKeyDown(sender, e);
            if ((e.KeyCode == Keys.Delete) && (this.gbList.RowCount != 0))
            {
                this.Delete();
            }
        }

        private void gbList_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            Common.Class.RowClickEventArgs args = new Common.Class.RowClickEventArgs(e.RowHandle, e.Column.ColumnHandle);
        }

        private void Init()
        {
            this.gcList.DataSource = new HRM_INSURANCE_MODIFY().GetList(this.m_InsuranceTableListID);
        }

        private void InitializeComponent()
        {
            this.rptPhoto = new RepositoryItemPictureEdit();
            this.gcList = new GridControl();
            this.gbList = new GridView();
            this.colEmployeeCode = new GridColumn();
            this.colEmployeeName = new GridColumn();
            this.colSocialInsuranceCode = new GridColumn();
            this.colHealthInsuranceCode = new GridColumn();
            this.colContentChange = new GridColumn();
            this.colOldContent = new GridColumn();
            this.colNewContent = new GridColumn();
            this.colReason = new GridColumn();
            this.layoutControl1 = new LayoutControl();
            this.layoutControlGroup1 = new LayoutControlGroup();
            this.layoutControlGroup2 = new LayoutControlGroup();
            this.layoutControlItem1 = new LayoutControlItem();
            this.rptPhoto.BeginInit();
            this.gcList.BeginInit();
            this.gbList.BeginInit();
            this.layoutControl1.BeginInit();
            this.layoutControl1.SuspendLayout();
            this.layoutControlGroup1.BeginInit();
            this.layoutControlGroup2.BeginInit();
            this.layoutControlItem1.BeginInit();
            base.SuspendLayout();
            this.rptPhoto.CustomHeight = 0x30;
            this.rptPhoto.Name = "rptPhoto";
            this.rptPhoto.NullText = "[Chưa chọn h\x00ecnh]";
            this.rptPhoto.SizeMode = PictureSizeMode.Zoom;
            this.gcList.EmbeddedNavigator.Buttons.Append.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Remove.Visible = false;
            this.gcList.EmbeddedNavigator.TextStringFormat = "{0}/{1}";
            this.gcList.Location = new Point(5, 0x19);
            this.gcList.MainView = this.gbList;
            this.gcList.Name = "gcList";
            this.gcList.RepositoryItems.AddRange(new RepositoryItem[] { this.rptPhoto });
            this.gcList.Size = new Size(0x33b, 0x1b4);
            this.gcList.TabIndex = 4;
            this.gcList.UseEmbeddedNavigator = true;
            this.gcList.ViewCollection.AddRange(new BaseView[] { this.gbList });
            this.gbList.Appearance.GroupRow.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.gbList.Appearance.GroupRow.Options.UseFont = true;
            this.gbList.Appearance.HeaderPanel.Options.UseTextOptions = true;
            this.gbList.Appearance.HeaderPanel.TextOptions.HAlignment = HorzAlignment.Center;
            this.gbList.Appearance.HeaderPanel.TextOptions.WordWrap = WordWrap.Wrap;
            this.gbList.BorderStyle = BorderStyles.NoBorder;
            this.gbList.Columns.AddRange(new GridColumn[] { this.colEmployeeCode, this.colEmployeeName, this.colSocialInsuranceCode, this.colHealthInsuranceCode, this.colContentChange, this.colOldContent, this.colNewContent, this.colReason });
            this.gbList.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gbList.GridControl = this.gcList;
            this.gbList.GroupPanelText = "K\x00e9o v\x00e0 Thả cột v\x00e0o đ\x00e2y để nh\x00f3m dữ liệu";
            this.gbList.IndicatorWidth = 40;
            this.gbList.Name = "gbList";
            this.gbList.OptionsBehavior.AllowIncrementalSearch = true;
            this.gbList.OptionsBehavior.AutoExpandAllGroups = true;
            this.gbList.OptionsBehavior.CopyToClipboardWithColumnHeaders = false;
            this.gbList.OptionsBehavior.FocusLeaveOnTab = true;
            this.gbList.OptionsLayout.StoreAllOptions = true;
            this.gbList.OptionsLayout.StoreAppearance = true;
            this.gbList.OptionsMenu.EnableColumnMenu = false;
            this.gbList.OptionsMenu.EnableGroupPanelMenu = false;
            this.gbList.OptionsNavigation.EnterMoveNextColumn = true;
            this.gbList.OptionsSelection.InvertSelection = true;
            this.gbList.OptionsSelection.MultiSelect = true;
            this.gbList.OptionsView.EnableAppearanceEvenRow = true;
            this.gbList.OptionsView.ShowAutoFilterRow = true;
            this.gbList.OptionsView.ShowGroupPanel = false;
            this.gbList.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(this.gbList_CustomDrawRowIndicator);
            this.gbList.KeyDown += new KeyEventHandler(this.gbList_KeyDown);
            this.gbList.DoubleClick += new EventHandler(this.gbList_DoubleClick);
            this.gbList.RowCellClick += new RowCellClickEventHandler(this.gbList_RowCellClick);
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.OptionsColumn.AllowEdit = false;
            this.colEmployeeCode.OptionsColumn.ReadOnly = true;
            this.colEmployeeCode.Width = 0x60;
            this.colEmployeeName.Caption = "Họ v\x00e0 t\x00ean";
            this.colEmployeeName.FieldName = "EmployeeName";
            this.colEmployeeName.Name = "colEmployeeName";
            this.colEmployeeName.OptionsColumn.AllowEdit = false;
            this.colEmployeeName.OptionsColumn.ReadOnly = true;
            this.colEmployeeName.Visible = true;
            this.colEmployeeName.VisibleIndex = 0;
            this.colEmployeeName.Width = 0x85;
            this.colSocialInsuranceCode.Caption = "Số sổ BHXH";
            this.colSocialInsuranceCode.FieldName = "SocialInsuranceCode";
            this.colSocialInsuranceCode.Name = "colSocialInsuranceCode";
            this.colSocialInsuranceCode.OptionsColumn.AllowEdit = false;
            this.colSocialInsuranceCode.OptionsColumn.ReadOnly = true;
            this.colSocialInsuranceCode.Visible = true;
            this.colSocialInsuranceCode.VisibleIndex = 1;
            this.colSocialInsuranceCode.Width = 0x41;
            this.colHealthInsuranceCode.Caption = "Số thẻ BHYT";
            this.colHealthInsuranceCode.FieldName = "HealthInsuranceCode";
            this.colHealthInsuranceCode.Name = "colHealthInsuranceCode";
            this.colHealthInsuranceCode.OptionsColumn.AllowEdit = false;
            this.colHealthInsuranceCode.OptionsColumn.ReadOnly = true;
            this.colHealthInsuranceCode.Visible = true;
            this.colHealthInsuranceCode.VisibleIndex = 2;
            this.colContentChange.Caption = "Nội dung thay đổi";
            this.colContentChange.FieldName = "ContentChange";
            this.colContentChange.Name = "colContentChange";
            this.colContentChange.OptionsColumn.AllowEdit = false;
            this.colContentChange.OptionsColumn.ReadOnly = true;
            this.colContentChange.Visible = true;
            this.colContentChange.VisibleIndex = 3;
            this.colContentChange.Width = 0xb1;
            this.colOldContent.Caption = "Cũ";
            this.colOldContent.FieldName = "OldContent";
            this.colOldContent.Name = "colOldContent";
            this.colOldContent.OptionsColumn.AllowEdit = false;
            this.colOldContent.OptionsColumn.ReadOnly = true;
            this.colOldContent.Visible = true;
            this.colOldContent.VisibleIndex = 4;
            this.colOldContent.Width = 0x5b;
            this.colNewContent.Caption = "Mới";
            this.colNewContent.FieldName = "NewContent";
            this.colNewContent.Name = "colNewContent";
            this.colNewContent.OptionsColumn.AllowEdit = false;
            this.colNewContent.OptionsColumn.ReadOnly = true;
            this.colNewContent.Visible = true;
            this.colNewContent.VisibleIndex = 5;
            this.colNewContent.Width = 0x65;
            this.colReason.Caption = "L\x00fd do điều chỉnh";
            this.colReason.FieldName = "Reason";
            this.colReason.Name = "colReason";
            this.colReason.OptionsColumn.AllowEdit = false;
            this.colReason.OptionsColumn.ReadOnly = true;
            this.colReason.Visible = true;
            this.colReason.VisibleIndex = 6;
            this.colReason.Width = 0xce;
            this.layoutControl1.Controls.Add(this.gcList);
            this.layoutControl1.Dock = DockStyle.Fill;
            this.layoutControl1.Location = new Point(0, 0);
            this.layoutControl1.Name = "layoutControl1";
            this.layoutControl1.Root = this.layoutControlGroup1;
            this.layoutControl1.Size = new Size(0x345, 0x1d2);
            this.layoutControl1.TabIndex = 5;
            this.layoutControl1.Text = "layoutControl1";
            this.layoutControlGroup1.CustomizationFormText = "layoutControlGroup1";
            this.layoutControlGroup1.EnableIndentsWithoutBorders = DefaultBoolean.True;
            this.layoutControlGroup1.GroupBordersVisible = false;
            this.layoutControlGroup1.Items.AddRange(new BaseLayoutItem[] { this.layoutControlGroup2 });
            this.layoutControlGroup1.Location = new Point(0, 0);
            this.layoutControlGroup1.Name = "layoutControlGroup1";
            this.layoutControlGroup1.Padding = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
            this.layoutControlGroup1.Size = new Size(0x345, 0x1d2);
            this.layoutControlGroup1.Spacing = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
            this.layoutControlGroup1.Text = "layoutControlGroup1";
            this.layoutControlGroup1.TextVisible = false;
            this.layoutControlGroup2.CustomizationFormText = "MẪU SỐ 03B-TBH: DANH S\x00c1CH ĐỀ NGHỊ ĐIỀU CHỈNH HỒ SƠ THAM GIA BHXH, BHYT";
            this.layoutControlGroup2.ExpandButtonVisible = true;
            this.layoutControlGroup2.Items.AddRange(new BaseLayoutItem[] { this.layoutControlItem1 });
            this.layoutControlGroup2.Location = new Point(0, 0);
            this.layoutControlGroup2.Name = "layoutControlGroup2";
            this.layoutControlGroup2.Padding = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
            this.layoutControlGroup2.Size = new Size(0x345, 0x1d2);
            this.layoutControlGroup2.Text = "MẪU SỐ 03B-TBH: DANH S\x00c1CH ĐỀ NGHỊ ĐIỀU CHỈNH HỒ SƠ THAM GIA BHXH, BHYT";
            this.layoutControlItem1.Control = this.gcList;
            this.layoutControlItem1.CustomizationFormText = "layoutControlItem1";
            this.layoutControlItem1.Location = new Point(0, 0);
            this.layoutControlItem1.Name = "layoutControlItem1";
            this.layoutControlItem1.Size = new Size(0x33f, 440);
            this.layoutControlItem1.Text = "layoutControlItem1";
            this.layoutControlItem1.TextSize = new Size(0, 0);
            this.layoutControlItem1.TextToControlDistance = 0;
            this.layoutControlItem1.TextVisible = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.layoutControl1);
            base.Name = "xuc03bTBH";
            base.Size = new Size(0x345, 0x1d2);
            this.rptPhoto.EndInit();
            this.gcList.EndInit();
            this.gbList.EndInit();
            this.layoutControl1.EndInit();
            this.layoutControl1.ResumeLayout(false);
            this.layoutControlGroup1.EndInit();
            this.layoutControlGroup2.EndInit();
            this.layoutControlItem1.EndInit();
            base.ResumeLayout(false);
        }

        public void LoadData(Guid InsuranceTableListID)
        {
            this.m_InsuranceTableListID = InsuranceTableListID;
            this.Init();
        }

        private void RaiseItemSelectedEventHander(HRM_INSURANCE_MODIFY item)
        {
            if (this.ItemSelected != null)
            {
                this.ItemSelected(this, item);
            }
        }

        public void ReLoad()
        {
            base.SetWaitDialogCaption("Đang nạp dữ liệu...");
            this.gcList.DataSource = new HRM_INSURANCE_MODIFY().GetList(this.m_InsuranceTableListID);
            base.SetWaitDialogCaption("Đang nạp cấu h\x00ecnh...");
            this.gbList.ClearColumnsFilter();
            base.SetWaitDialogCaption("Đ\x00e3 xong...");
            this.DoHide();
        }

        private void Select()
        {
            base.Select();
        }

        private void ucList_ListKeyDown(object sender, KeyEventArgs key)
        {
            if (key.KeyCode == Keys.F2)
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.E))
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if (key.KeyCode == Keys.Enter)
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if (key.KeyCode == Keys.F5)
            {
                this.ReLoad();
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.N))
            {
                this.Add();
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.T))
            {
                this.Add();
            }
        }

        public delegate void ItemSelectedEventHander(object sender, HRM_INSURANCE_MODIFY item);
    }
}

